﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Frontdatabase.Migrations
{
    /// <inheritdoc />
    public partial class 添加视频表视频列表表视频合集表 : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "VideoCompilations",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false, comment: "自增主键")
                        .Annotation("SqlServer:Identity", "1, 1"),
                    Synopsis = table.Column<string>(type: "nvarchar(max)", nullable: true, comment: "合集简介"),
                    Create_Time = table.Column<DateTime>(type: "datetime2", nullable: false, comment: "创建时间"),
                    UpDate_Time = table.Column<DateTime>(type: "datetime2", nullable: false, comment: "更新时间")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_VideoCompilations", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "VideoList",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false, comment: "自增主键")
                        .Annotation("SqlServer:Identity", "1, 1"),
                    Title = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false, comment: "投稿视频标题"),
                    VideoType = table.Column<int>(type: "int", nullable: false, comment: "投稿视频的类型: 自制 转载"),
                    Cover = table.Column<string>(type: "nvarchar(max)", nullable: false, comment: "视频封面 的地址"),
                    Synopsis = table.Column<string>(type: "nvarchar(max)", nullable: true, comment: "投稿视频简介"),
                    DanmuCount = table.Column<int>(type: "int", nullable: false),
                    Size = table.Column<int>(type: "int", nullable: false),
                    ZanSize = table.Column<int>(type: "int", nullable: false),
                    WacthCount = table.Column<int>(type: "int", nullable: false),
                    UserId = table.Column<int>(type: "int", nullable: false),
                    VideoCompilationsId = table.Column<int>(type: "int", nullable: false),
                    Create_Time = table.Column<DateTime>(type: "datetime2", nullable: false, comment: "创建时间"),
                    UpDate_Time = table.Column<DateTime>(type: "datetime2", nullable: false, comment: "更新时间")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_VideoList", x => x.Id);
                    table.ForeignKey(
                        name: "FK_VideoList_VideoCompilations_VideoCompilationsId",
                        column: x => x.VideoCompilationsId,
                        principalTable: "VideoCompilations",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_VideoList_bilibli_user_UserId",
                        column: x => x.UserId,
                        principalTable: "bilibli_user",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                },
                comment: "视频列表 一个视频必需属于一个视频列表\r\n                即使用户只上传一个视频 也要创建一个列表并把视频放入列表中\r\n                ");

            migrationBuilder.CreateTable(
                name: "VideoEntities",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false, comment: "自增主键")
                        .Annotation("SqlServer:Identity", "1, 1"),
                    Name = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false, comment: "视频文件名"),
                    Duration = table.Column<long>(type: "bigint", nullable: false, comment: "视频时长 单位s"),
                    Size = table.Column<int>(type: "int", nullable: false, comment: "视频容量大小 最大5*1024Mb"),
                    Index = table.Column<int>(type: "int", nullable: false, comment: "视频在视频列表中的排序"),
                    Src = table.Column<string>(type: "nvarchar(max)", nullable: false, comment: "视频地址"),
                    VideoListId = table.Column<int>(type: "int", nullable: false),
                    Create_Time = table.Column<DateTime>(type: "datetime2", nullable: false, comment: "创建时间"),
                    UpDate_Time = table.Column<DateTime>(type: "datetime2", nullable: false, comment: "更新时间")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_VideoEntities", x => x.Id);
                    table.ForeignKey(
                        name: "FK_VideoEntities_VideoList_VideoListId",
                        column: x => x.VideoListId,
                        principalTable: "VideoList",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                },
                comment: "单个视频 记录视频的基本信息");

            migrationBuilder.CreateIndex(
                name: "IX_VideoEntities_VideoListId",
                table: "VideoEntities",
                column: "VideoListId");

            migrationBuilder.CreateIndex(
                name: "IX_VideoList_UserId",
                table: "VideoList",
                column: "UserId");

            migrationBuilder.CreateIndex(
                name: "IX_VideoList_VideoCompilationsId",
                table: "VideoList",
                column: "VideoCompilationsId");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "VideoEntities");

            migrationBuilder.DropTable(
                name: "VideoList");

            migrationBuilder.DropTable(
                name: "VideoCompilations");
        }
    }
}
